{-# OPTIONS -Wall #-}

module DemoLong where


import Majalan.Base
-- import Majalan.Base.Chain

import Majalan.Symbolic.ET12Pitch
import Majalan.Symbolic.ET12PitchNames

import Data.Monoid


data Orch = CRUNCH | WG_BOWED_BAR
  deriving (Eq,Ord,Show)

instance CsOrch Orch where
  instNumber CRUNCH             = 1
  instNumber WG_BOWED_BAR       = 2


crunch :: Decimal -> Decimal -> Event uctx ()
crunch iamp idamp = 
    makeEvent CRUNCH () (const [ VFloat iamp, VFloat idamp ])

fwcrunch :: Decimal -> Decimal -> EventFw uctx ()
fwcrunch iamp idamp = fixWidth 1.0 $ crunch iamp idamp



wgBowedBar :: Decimal -> ET12 -> Decimal -> EventFw uctx ()
wgBowedBar iamp ipch iconst = 
    makeEventFw WG_BOWED_BAR () 2.0 (const [ VFloat iamp
                                           , VFloat $ toHertz 440.0 ipch
                                           , VFloat iconst
                                           ])
                              
-- | Time varies in amplitude
wgBowedBarB1 :: ET12 -> Decimal -> EventFwB1 Decimal uctx () 
wgBowedBarB1 ipch iconst = \ampb1 -> wgBowedBar ampb1 ipch iconst 


type MyCtx = ()

ctx_zero :: MyCtx
ctx_zero = ()


score01 :: ScoreObj 
score01 = score (regularTimeline (12,8) 120) ctx_zero $ do 
    _sys1 <- namedPart_ "bowed bar" $ do 
                { eventList 0 $ metricSequence bb_intro intro_patt
                } 
    return ()



bb_intro :: BarParser uctx impl ()
bb_intro = count_ 8 $ p1 <> p2 <> p3 <> p4
  where
    p1 = allBeats (\_ -> unfixWidth $ wgBowedBar 0.4 c_3 0)
    p2 = allBeats (\_ -> unfixWidth $ wgBowedBar 0.4 d_3 0)
    p3 = allBeatsList [c_3 , d_3]  (\_ p -> unfixWidth $ wgBowedBar 0.4 p 0) 
    p4 = allBeatsCyc [c_3 , d_3, e_3, f_3]  (\_ p -> unfixWidth $ wgBowedBar 0.4 p 0) 
  


intro_patt :: BeatPattern ()
intro_patt = nbars 8 $ bar1 <> bar1 <> bar2 <> bar2

bar1 :: BeatPattern ()
bar1 = divisions [ 2,1, 2,1, 2,1, 2,1 ]

bar2 :: BeatPattern ()
bar2 = divisions [ 2,1, 1,2,  2,1, 1,2 ]


col_specs :: ColumnSpecs
col_specs = columnSpecs [ (CRUNCH, cols_crunch)
                        , (WG_BOWED_BAR, cols_bowed_bar) ]
  where             
    cols_crunch  = [ defaultFormat "amp", defaultFormat "damp" ]
    cols_bowed_bar  = [ defaultFormat "amp", defaultFormat "pch"
                      , defaultFormat "const" ]


    


demo01 :: IO ()
demo01 = shellTest odac "orc/demo_orc.orc" $ renderScoreObj col_specs score01

